// @vitest-environment jsdom
//
// The [locale] mirror pages re-export the bare pages and add getStaticPaths,
// which tells `voltro build` which locale-prefixed paths to emit. The default
// locale (en) is NOT listed — it lives at the bare path. The docs [...slug]
// mirror is the interesting case: a DYNAMIC route under a DYNAMIC locale
// segment, so its getStaticPaths must emit the CROSS-PRODUCT of every
// non-default locale × every doc slug.

import { describe, expect, test, vi } from 'vitest'

// The mirrors transitively import the base pages, which import @voltro/i18n
// and @voltro/web. Stub both so importing the modules doesn't require the
// real runtimes.
vi.mock('@voltro/web', () => ({
  useLocation: () => '/',
  useParams: () => ({ slug: '' }),
}))

vi.mock('@voltro/i18n', () => ({
  // The locale catalogs call these at module top-level; identity mirrors the
  // real (compile-time-only) implementations so importing them doesn't throw.
  defineCatalog: <T,>(c: T): T => c,
  defineLocale:
    () =>
    <T,>(c: T): T =>
      c,
  useLocale: () => 'en',
  useTFn: () => (id: string) => id,
  T: ({ id }: { id: string }) => id,
}))

const indexMirror = await import('./page')
const slugMirror = await import('./docs/[...slug]/page')

describe('home mirror — getStaticPaths', () => {
  test('emits only non-default locales (just /de)', async () => {
    const paths = await indexMirror.getStaticPaths()
    expect(paths).toEqual([{ params: { locale: 'de' } }])
  })

  test('re-exports the base page component + its meta function', () => {
    expect(typeof indexMirror.default).toBe('function')
    expect(indexMirror.meta({ locale: 'de' }).title).toBe('Dokumentation')
    expect(indexMirror.renderMode).toBe('static')
    expect(indexMirror.interactive).toBe('none')
  })
})

describe('docs [...slug] mirror — getStaticPaths (locale × slug cross-product)', () => {
  test('emits every non-default locale paired with every doc slug', async () => {
    const paths = await slugMirror.getStaticPaths()
    expect(paths).toEqual([
      { params: { locale: 'de', slug: 'intro/getting-started' } },
      { params: { locale: 'de', slug: 'guides/first-page' } },
    ])
  })

  test('re-exports the base page component + its per-locale meta function', () => {
    expect(typeof slugMirror.default).toBe('function')
    expect(
      slugMirror.meta({ locale: 'de', params: { slug: 'guides/first-page' } }).title,
    ).toBe('Deine erste Seite')
    expect(slugMirror.renderMode).toBe('static')
    expect(slugMirror.interactive).toBe('none')
  })
})
